/// ------------------------------------------------------------------租金监听事件-------------------------------------------------------------
//租金折扣  监听
$("#discount").change(function() {
    discount();
});
//实收租金  监听
$("#realMonthlyRentFee").change(function() {
    ninetyPercentRealMonthlyFee();
    totalMonthRealFee();
});
//实收物业  监听
$("#realPropertyFee").change(function() {
    totalMonthRealFee();
});
//实收租金百分之90
function ninetyPercentRealMonthlyFee() {
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/ninetyPercentRealMonthlyFee",
        data : {
            "realMonthlyRentFee": $("#realMonthlyRentFee").val()
        },
        async : false,
        success : function(data) {
            $("#ninetyPercentRealMonthlyFeeTemp").val(data.temp);
            $("#ninetyPercentRealMonthlyFee").val(data.realValue);
        }
    });
};
//宽带费  监听
$("#wlanFee").change(function() {
    totalMonthRealFee();
});

// ------------------------------------------------------------------电费监听事件-------------------------------------------------------------
//上月电度数  监听
$("#lastMonthEletableNumber").change(function() {
    //电费相关
    useElectricNumber();
    totalElectricNumber();
    useElectricFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();

});
//本月电度数  监听
$("#thisMonthEletableNumber").change(function() {
    //电费相关
    useElectricNumber();
    totalElectricNumber();
    useElectricFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();
});
//电公摊基数  监听
$("#electricApportionBaseNumber").change(function() {
    //电费相关
    apportionElectricNumber();
    totalElectricNumber();
    apportionElectricFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();
});
//电费单价  监听
$("#electricUninPrice").change(function() {
    useElectricFee();
    apportionElectricFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();
});
//本月用电
function useElectricNumber() {
    var thisMonthEletableNumber = 0;
    if($("#thisMonthEletableNumber").val()!=null && $("#thisMonthEletableNumber").val()!=''){
        thisMonthEletableNumber = $("#thisMonthEletableNumber").val();
    }
    var lastMonthEletableNumber = 0;
    if($("#lastMonthEletableNumber").val()!=null && $("#lastMonthEletableNumber").val()!=''){
        lastMonthEletableNumber = $("#lastMonthEletableNumber").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/useElectricNumber",
        data : {
            "thisMonthEletableNumber": thisMonthEletableNumber,
            "lastMonthEletableNumber": lastMonthEletableNumber
        },
        async : false,
        success : function(data) {
            $("#useElectricNumberTemp").val(data.temp);
            $("#useElectricNumber").val(data.realValue);
        }
    });
};
//公摊电度数
function apportionElectricNumber() {
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/apportionElectricNumber",
        data : {
            "apportionRatioOver": new Number($("#apportionRatio").val()),
            "electricApportionBaseNumber": $("#electricApportionBaseNumber").val()
        },
        async : false,
        success : function(data) {
            $("#apportionElectricNumberTemp").val(data.temp);
            $("#apportionElectricNumber").val(data.realValue);
        }
    });
};
//总用电度数
function totalElectricNumber() {
    var useElectricNumber = 0;
    if($("#useElectricNumber").val()!=null && $("#useElectricNumber").val()!=''){
        useElectricNumber = $("#useElectricNumber").val();
    }
    var apportionElectricNumber = 0;
    if($("#apportionElectricNumber").val()!=null && $("#apportionElectricNumber").val()!=''){
        apportionElectricNumber = $("#apportionElectricNumber").val();
    }
    $.ajax({
        cache : false,
        type : "POST",
        url : ctx + "system/backlog/totalElectricNumber",
        data : {
            "useElectricNumber": useElectricNumber,
            "apportionElectricNumber": apportionElectricNumber
        },
        async : false,
        success : function(data) {
            console.log('11111')
            $("#totalElectricNumberTemp").val(data.temp);
            $("#totalElectricNumber").val(data.realValue);
        }
    });
};
//自用电费
function useElectricFee() {
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/useElectricFee",
        data : {
            "useElectricNumber": $("#useElectricNumber").val(),
            "electricUninPrice": $("#electricUninPrice").val()
        },
        async : false,
        success : function(data) {
            $("#useElectricFeeTemp").val(data.temp);
            $("#useElectricFee").val(data.realValue);
        }
    });
};
//公摊电费
function apportionElectricFee() {
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/apportionElectricFee",
        data : {
            "apportionElectricNumber": $("#apportionElectricNumber").val(),
            "electricUninPrice": $("#electricUninPrice").val()
        },
        async : false,
        success : function(data) {
            $("#apportionElectricFeeTemp").val(data.temp);
            $("#apportionElectricFee").val(data.realValue);
        }
    });
};

// -----------------------------------------------------------------水费监听事件-------------------------------------------------------------
//上月水表度数  监听
$("#lastMonthWatableNumber").change(function() {
    //水费相关
    useWaterNumber()
    totalWaterNumber();
    useWaterFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();
});
//本月水表度数  监听
$("#thisMonthWatableNumber").change(function() {
    //水费相关
    useWaterNumber();
    totalWaterNumber();
    useWaterFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();
});
//水公摊基数  监听
$("#waterApportionBaseNumber").change(function() {
    //水费相关
    apportionWaterNumber();
    totalWaterNumber();
    apportionWaterFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();
});
//水费单价  监听
$("#waterUninPrice").change(function() {
    //水费相关
    useWaterFee();
    apportionWaterFee();
    //合计相关
    totalUtilityFee();
    totalMonthRealFee();
    useTotalUtilityFee();
    apportionTotalUtilityFee();
});
//本月用水
function useWaterNumber() {
    var thisMonthWatableNumber = 0;
    if($("#thisMonthWatableNumber").val()!=null && $("#thisMonthWatableNumber").val()!=''){
        thisMonthWatableNumber = $("#thisMonthWatableNumber").val();
    }
    var lastMonthWatableNumber = 0;
    if($("#lastMonthWatableNumber").val()!=null && $("#lastMonthWatableNumber").val()!=''){
        lastMonthWatableNumber = $("#lastMonthWatableNumber").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/useWaterNumber",
        data : {
            "thisMonthWatableNumber": thisMonthWatableNumber,
            "lastMonthWatableNumber": lastMonthWatableNumber
        },
        async : false,
        success : function(data) {
            $("#useWaterNumberTemp").val(data.temp);
            $("#useWaterNumber").val(data.realValue);
        }
    });
};
//公摊水度数
function apportionWaterNumber() {
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/apportionWaterNumber",
        data : {
            "apportionRatioOver": new Number($("#apportionRatio").val()),
            "waterApportionBaseNumber": $("#waterApportionBaseNumber").val()
        },
        async : false,
        success : function(data) {
            $("#apportionWaterNumberTemp").val(data.temp);
            $("#apportionWaterNumber").val(data.realValue);
        }
    });
};
//总用水度数
function totalWaterNumber() {
    var useWaterNumber = 0;
    if($("#useWaterNumber").val()!=null && $("#useWaterNumber").val()!=''){
        useWaterNumber = $("#useWaterNumber").val();
    }
    var apportionWaterNumber = 0;
    if($("#apportionWaterNumber").val()!=null && $("#apportionWaterNumber").val()!=''){
        apportionWaterNumber = $("#apportionWaterNumber").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/totalWaterNumber",
        data : {
            "useWaterNumber": useWaterNumber,
            "apportionWaterNumber": apportionWaterNumber
        },
        async : false,
        success : function(data) {
            $("#totalWaterNumberTemp").val(data.temp);
            $("#totalWaterNumber").val(data.realValue);
        }
    });
};
//自用水费
function useWaterFee() {
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/useWaterFee",
        data : {
            "useWaterNumber": $("#useWaterNumber").val(),
            "waterUninPrice": $("#waterUninPrice").val()
        },
        async : false,
        success : function(data) {
            $("#useWaterFeeTemp").val(data.temp);
            $("#useWaterFee").val(data.realValue);
        }
    });
};
//公摊水费
function apportionWaterFee() {
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/apportionWaterFee",
        data : {
            "apportionWaterNumber": $("#apportionWaterNumber").val(),
            "waterUninPrice": $("#waterUninPrice").val()
        },
        async : false,
        success : function(data) {
            $("#apportionWaterFeeTemp").val(data.temp);
            $("#apportionWaterFee").val(data.realValue);
        }
    });
};
// -----------------------------------------------------------------合计费用监听事件-------------------------------------------------------------
//水电费合计
function totalUtilityFee() {
    var useElectricFee = 0;
    if($("#useElectricFee").val()!=null && $("#useElectricFee").val()!=''){
        useElectricFee = $("#useElectricFee").val();
    }
    var useWaterFee = 0;
    if($("#useWaterFee").val()!=null && $("#useWaterFee").val()!=''){
        useWaterFee = $("#useWaterFee").val();
    }
    var apportionElectricFee = 0;
    if($("#apportionElectricFee").val()!=null && $("#apportionElectricFee").val()!=''){
        apportionElectricFee = $("#apportionElectricFee").val();
    }
    var apportionWaterFee = 0;
    if($("#apportionWaterFee").val()!=null && $("#apportionWaterFee").val()!=''){
        apportionWaterFee = $("#apportionWaterFee").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/totalUtilityFee",
        data : {
            "useElectricFee": useElectricFee,
            "useWaterFee": useWaterFee,
            "apportionElectricFee": apportionElectricFee,
            "apportionWaterFee": apportionWaterFee,
        },
        async : false,
        success : function(data) {
            $("#totalUtilityFeeTemp").val(data.temp);
            $("#totalUtilityFee").val(data.realValue);
        }
    });
};
//自用水电费合计
function useTotalUtilityFee() {
    var useElectricFee = 0;
    if($("#useElectricFee").val()!=null && $("#useElectricFee").val()!=''){
        useElectricFee = $("#useElectricFee").val();
    }
    var useWaterFee = 0;
    if($("#useWaterFee").val()!=null && $("#useWaterFee").val()!=''){
        useWaterFee = $("#useWaterFee").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/useTotalUtilityFee",
        data : {
            "useElectricFee": useElectricFee,
            "useWaterFee": useWaterFee
        },
        async : false,
        success : function(data) {
            $("#useTotalUtilityFeeTemp").val(data.temp);
            $("#useTotalUtilityFee").val(data.realValue);
        }
    });
};
//公摊水电费合计
function apportionTotalUtilityFee() {
    var apportionElectricFee = 0;
    if($("#apportionElectricFee").val()!=null && $("#apportionElectricFee").val()!=''){
        apportionElectricFee = $("#apportionElectricFee").val();
    }
    var apportionWaterFee = 0;
    if($("#apportionWaterFee").val()!=null && $("#apportionWaterFee").val()!=''){
        apportionWaterFee = $("#apportionWaterFee").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/apportionTotalUtilityFee",
        data : {
            "apportionElectricFee": apportionElectricFee,
            "apportionWaterFee": apportionWaterFee
        },
        async : false,
        success : function(data) {
            $("#apportionTotalUtilityFeeTemp").val(data.temp);
            $("#apportionTotalUtilityFee").val(data.realValue);
        }
    });
};
//本月实收金额合计
function totalMonthRealFee() {
    var totalUtilityFee = 0;
    if($("#totalUtilityFee").val()!=null && $("#totalUtilityFee").val()!=''){
        totalUtilityFee = $("#totalUtilityFee").val();
    }
    var realPropertyFee = 0;
    if($("#realPropertyFee").val()!=null && $("#realPropertyFee").val()!=''){
        realPropertyFee = $("#realPropertyFee").val();
    }
    var realMonthlyRentFee = 0;
    if($("#realMonthlyRentFee").val()!=null && $("#realMonthlyRentFee").val()!=''){
        realMonthlyRentFee = $("#realMonthlyRentFee").val();
    }
    var wlanFee = 0;
    if($("#wlanFee").val()!=null && $("#wlanFee").val()!=''){
        wlanFee = $("#wlanFee").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/totalMonthRealFee",
        data : {
            "totalUtilityFee": totalUtilityFee,
            "realPropertyFee": realPropertyFee,
            "realMonthlyRentFee": realMonthlyRentFee,
            "wlanFee": wlanFee
        },
        async : false,
        success : function(data) {
            $("#totalMonthRealFeeTemp").val(data.temp);
            $("#totalMonthRealFee").val(data.realValue);
        }
    });
};
//租金折扣触发
function discount() {
    var discount = 100;
    if($("#discount").val()!=null && $("#discount").val()!=''){
        discount = $("#discount").val();
    }
    var mon = 0;
    if($("#monthlyRentFee").val()!=null && $("#monthlyRentFee").val()!=''){
        monthlyRentFee = $("#monthlyRentFee").val();
    }
    $.ajax({
        cache : true,
        type : "POST",
        url : ctx + "system/backlog/discount",
        data : {
            "discount": discount,
            "monthlyRentFee": monthlyRentFee
        },
        async : false,
        success : function(data) {
            $("#realMonthlyRentFee").val(data.realValue);
            ninetyPercentRealMonthlyFee();
            totalMonthRealFee();
        }
    });
};